package operations;

import book.Booklist;

import javax.crypto.spec.PSource;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 */
public class BorrowOperation implements IOperation{
    //借阅图书
    @Override
    public void work(Booklist booklist) {
        System.out.println("借阅图书");
        System.out.print("请输入你要借阅图书的名字:");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        for (int i = 0; i < booklist.getUsedSize(); i++) {
            if(name.equals(booklist.getBooks()[i].getName())){
                if(booklist.getBooks()[i].getBorrowed()){
                    System.out.println("该书已借出！");
                    return;
                }else{
                    booklist.getBooks()[i].setBorrowed(true);
                    System.out.println("借阅成功！");
                    return;
                }

            }
        }
        System.out.println("没有这本书！");
    }
}
